package com.summer.user.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.summer.dingding.model.DingDingUser;

@Entity
@Table(name = "user_info")
@NamedQueries({
	@NamedQuery(name = "User.findUserByUsername", query = "from User u where u.username = ?"),
	@NamedQuery(name = "User.findUserByEmail", query = "from User u where u.email = ?"),
	@NamedQuery(name = "User.findUserbymobileNumber", query = "from User u where u.mobileNumber = ?") })
public class User implements Serializable{

	private static final long serialVersionUID = -7385701219543468178L;
	private String id;
	private String username;
	private String photo;
	private String email;
	private String password;
	private String status;
	private String realname;
	private String sex;
	private String cashPassword;
	private Date birthday;
	private String homeAddress;
	private String qq;
	private String msn;
	private String mobileNumber;
	private String idCard;
	private String currentAddress;
	private String nickname;
	private String securityQuestion1;
	private String securityQuestion2;
	private String securityAnswer1;
	private String securityAnswer2;
	private Date lastLoginTime;
	private Date registerTime;
	private String comment;
	private List<Role> roles = new ArrayList<Role>();
	private Date disableTime;
	
	private Positions position;
	
	/**绑定的登录ip，如果是多个，用英文逗号分隔。为空则不限制登录ip*/
	private String bindIP;
	private DingDingUser duser;

	@Id
	@Column(name = "id" , unique = true , nullable = false)
	public String getId() {
		return id;
	}

	@Column(name = "username")
	public String getUsername() {
		return username;
	}
	
	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "role_id", nullable = false, updatable = false) })
	public List<Role> getRoles() {
		return this.roles;
	}
	

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "email", length = 100)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "o_password", nullable = false, length = 100)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "realname", length = 10)
	public String getRealname() {
		return this.realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	@Column(name = "sex", length = 2)
	public String getSex() {
		return this.sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "birthday", length = 10)
	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Column(name = "home_address", length = 100)
	public String getHomeAddress() {
		return this.homeAddress;
	}

	public void setHomeAddress(String homeAddress) {
		this.homeAddress = homeAddress;
	}

	@Column(name = "QQ", length = 12)
	public String getQq() {
		return this.qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	@Column(name = "MSN", length = 100)
	public String getMsn() {
		return this.msn;
	}

	public void setMsn(String msn) {
		this.msn = msn;
	}

	@Column(name = "mobile_number", length = 18)
	public String getMobileNumber() {
		return this.mobileNumber;
	}

	public void setMobileNumber(String mobileNumber) {
		this.mobileNumber = mobileNumber;
	}

	@Column(name = "id_card", length = 20)
	public String getIdCard() {
		return this.idCard;
	}

	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}

	@Column(name = "current_address", length = 100)
	public String getCurrentAddress() {
		return this.currentAddress;
	}

	public void setCurrentAddress(String currentAddress) {
		this.currentAddress = currentAddress;
	}

	@Column(name = "nickname", length = 50)
	public String getNickname() {
		return this.nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	@Column(name = "security_question1", length = 100)
	public String getSecurityQuestion1() {
		return this.securityQuestion1;
	}

	public void setSecurityQuestion1(String securityQuestion1) {
		this.securityQuestion1 = securityQuestion1;
	}

	@Column(name = "security_question2", length = 100)
	public String getSecurityQuestion2() {
		return this.securityQuestion2;
	}

	public void setSecurityQuestion2(String securityQuestion2) {
		this.securityQuestion2 = securityQuestion2;
	}

	@Column(name = "security_answer1", length = 100)
	public String getSecurityAnswer1() {
		return this.securityAnswer1;
	}

	public void setSecurityAnswer1(String securityAnswer1) {
		this.securityAnswer1 = securityAnswer1;
	}

	@Column(name = "security_answer2", length = 100)
	public String getSecurityAnswer2() {
		return this.securityAnswer2;
	}

	public void setSecurityAnswer2(String securityAnswer2) {
		this.securityAnswer2 = securityAnswer2;
	}

	@Column(name = "last_login_time", length = 19)
	public Date getLastLoginTime() {
		return this.lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	@Column(name = "register_time", nullable = false, length = 19)
	public Date getRegisterTime() {
		return this.registerTime;
	}

	public void setRegisterTime(Date registerTime) {
		this.registerTime = registerTime;
	}

	@Column(name = "o_comment", length=2000)
	public String getComment() {
		return this.comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	@Column(name = "status", nullable = false)
	public String getStatus() {
		return this.status;
	}

	@Column(name = "cash_password", length = 50)
	public String getCashPassword() {
		return this.cashPassword;
	}

	public void setCashPassword(String cashPassword) {
		this.cashPassword = cashPassword;
	}

	public void setStatus(String status) {
		this.status = status;
	}


	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	@Column(name = "photo", length = 500)
	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	@Column(name = "disable_time")
	public Date getDisableTime() {
		return disableTime;
	}

	public void setDisableTime(Date disableTime) {
		this.disableTime = disableTime;
	}

	public String getBindIP() {
		return bindIP;
	}

	public void setBindIP(String bindIP) {
		this.bindIP = bindIP;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "position_id")
	public Positions getPosition() {
		return position;
	}

	public void setPosition(Positions position) {
		this.position = position;
	}

	@OneToOne(mappedBy = "user",cascade = CascadeType.ALL)
	public DingDingUser getDuser() {
		return duser;
	}
	
	public void setDuser(DingDingUser duser) {
		this.duser = duser;
	}

	

	
}
